package com.yyk.yykywd.mvvm.view_model

import androidx.lifecycle.MutableLiveData
import com.yyk.yykywd.CALL_BACK
import com.yyk.yykywd.FROM_POTENTIAL_CUSTOMER_HOSPITAL
import com.yyk.yykywd.VISIT_AGAIN
import com.yyk.yykywd.bean.BaseBean
import com.yyk.yykywd.mvvm.entity.FollowTypeBean
import com.yyk.yykywd.mvvm.entity.TypeBean
import com.yyk.yykywd.mvvm.model.CustomerModel
import com.yyk.yykywd.mvvm.model.FollowModel
import com.yyk.yykywd.mvvm.model.GetBase

/**
 * 文件描述：
 * Created by guo on 2019-11-22.
 */
class BusinessFollowViewModel : BaseViewModel() {
    var id: String = ""
    var followId: String = ""
    var type: String = ""
    var name = ""
    var position = ""
    var phone = ""
    var mid = ""
    var inviteResult: Boolean = true
    private val followModel = FollowModel()
    lateinit var followTypeBean: FollowTypeBean
    var hospitalFollowType: List<String> = ArrayList()
    var agentFollowType: List<String> = ArrayList()

    var followType = MutableLiveData<FollowTypeBean>()

    fun getType() {
        followModel.getType(object : FollowModel.GetFollowType {
            override fun getInfo(type: FollowTypeBean) {
                followTypeBean = type
                hospitalFollowType = type.hos_data.map { it.name }
                agentFollowType = type.agent_data.map { it.name }
                if (this@BusinessFollowViewModel.type == FROM_POTENTIAL_CUSTOMER_HOSPITAL) {
                    for (hosDatum in type.hos_data) {
                        if (hosDatum.name == VISIT_AGAIN) {
                            followId = hosDatum.id
                        }
                    }
                } else {
                    for (agDatum in type.agent_data) {
                        if (agDatum.name == CALL_BACK) {
                            followId = agDatum.id
                        }
                    }
                }
                followType.value = type
            }

            override fun onError(e: String) {
            }

        })
    }

    fun saveFollow(follow_situation:String) {
        var m_type = ""
        if (inviteResult) {
            m_type = "1"
        } else {
            m_type = "2"
        }
        followModel.saveFollow(type = type,
                id = id,
                followId = followId,
                content = follow_situation,
                name = name,
                position = position,
                phone = phone,
                mid = mid,
                m_type = m_type,
                m_text = follow_situation,
                getBase = object : GetBase {
                    override fun getInfo(base: BaseBean) {
                        setBaseValue(base)
                    }

                    override fun onError(e: String) {

                    }
                })
    }
}